package chatclient_01.dialogs;

import chatclient_01.ChatClient;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;

public class NameListDialog extends JDialog {

  ChatClient client;
  private JButton jButton1;
  private JList jList1;
  private JScrollPane jScrollPane1;

  public NameListDialog(ChatClient parent, boolean modal) {
    super(parent, modal);
    initComponents();
    this.client = parent;
  }

  private void initComponents() {
    this.jScrollPane1 = new JScrollPane();
    this.jList1 = new JList();
    this.jButton1 = new JButton();

    setDefaultCloseOperation(2);
    addComponentListener(new ComponentAdapter() {

      public void componentShown(ComponentEvent evt) {
        NameListDialog.this.formComponentShown(evt);
      }
    });
    this.jList1.setSelectionMode(0);
    this.jScrollPane1.setViewportView(this.jList1);

    this.jButton1.setText("OK");
    this.jButton1.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent evt) {
        NameListDialog.this.jButton1ActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(2, 2, 2).addComponent(this.jScrollPane1, -2, 116, -2).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(this.jButton1, -2, 63, -2).addContainerGap(-1, 32767)));

    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jScrollPane1, -1, 185, 32767).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(151, 32767).addComponent(this.jButton1).addContainerGap()));

    pack();
  }

  private void formComponentShown(ComponentEvent evt) {
    this.jList1.setModel(this.client.getNameListModel());
  }

  private void jButton1ActionPerformed(ActionEvent evt) {
    this.client.setSelectedName(this.jList1.getSelectedIndex());
    setVisible(false);
  }
}